function validateLoginForm() {
    var userName = document.getElementsByName("usernameLog")[0].value;
    var password = document.getElementsByName("passwordLog")[0].value;
    
    var errorList = new Array();
    if (userName == null || userName == "") {
        errorList.push('Empty username');
    }
    if (password == null || password == "") {
        errorList.push('Empty password');
    }
    
    if (errorList.length > 0) {
        showErrorList(errorList);
        return false;
    } else {
        return true;
    }
}

function validateAndLogin(){
    if(validateLoginForm()){
        var form = $("#login-form");
        $.post($(form).attr("action"), $(form).serialize(), function(data){
            if(data.authenticated){
                location.href = data.location;
            }else{
                showError(data.error);
            }
        }, "json");
    }
    return false;
}